<template>
 <el-dialog 
   width="80%" 
  :close-on-click-modal="false"
  :title="title"
  :model-value="isShow"
  @open="onOpen">
    <el-form
      ref="form"
      :inline="true"
      :model="form"
      :rules="rules"
      label-width="80px"
    >
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="信用代码" prop="creditCode">
        <el-input v-model="form.creditCode" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="onCancel">取消</el-button>
      <el-button type="primary" @click="onSave">确认</el-button>
    </template>
  </el-dialog>
</template>

<script>
// import the component
//import Treeselect from "@riophae/vue-treeselect";
// import the styles
//import "@riophae/vue-treeselect/dist/vue-treeselect.css";

import { getDetail, add, save } from '@/api/admin/tentant'
export default {
   //components: { Treeselect },
  props: {
    data: {
      required: true,
      type: String,
      default: ''
    },
    isShow: {
      require: true,
      type: Boolean,
      default: false
    },
    title: {
      require: true,
      type: String,
      default: ""
    }
  },
  emits: ['onChange','update:isShow'],
  data() {
    return {
      form: {},
      rules: {},
    
    }
  },
  mounted() {

  },
  methods: {
    async onOpen() {
      if(this.data) {
        const user = await getDetail(this.data)
        this.form = user.result
      }
      else {
        this.form = {
          name:'',
          creditCode: ''
        }
      }
      
    },
    async onSave() {

      await save(this.form)
     
      this.$emit("onChange", this.form)
      this.$emit("update:isShow", false)
    },
    onCancel() {
      this.$emit("update:isShow", false)
    },
    onClose() {

    }
  },
  watch: {
    'data': async function() {
      
    }
  }
}
</script>


